# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity_study_code
File Name: 将eab23js数据中的数据替换.py
Author: kij
Create Date: 2021/8/24
-------------------------------------------------
"""
import os
import re

from module_seven.fpjs import arrayjm

_0x56af = ['ZXJydg==', '5b2T5YmN6aG16Z2i54mI5pys6L6D5L2O77yM6K+35oyJQ1RSTC1GNeWIt+aWsOmhtemdou+8gQ==', 'YXR0cg==', 'c3Jj', 'ZGF0YTppbWFnZS9wbmc7YmFzZTY0LA==', 'I3l6bWluZm8=', 'dGV4dA==', '6K+36L6T5YWl6aqM6K+B56CB5paH5a2X', 'aHRtbA==', '6K+36L6T5YWl6aqM6K+B56CB5Zu+54mH5LitPGZvbnQgY29sb3I9InJlZCIgc2l6ZT0iNCIgc3R5bGU9ImJhY2tncm91bmQ6I0MwQzBDMCI+57qi6ImyPC9mb250PuaWh+Wtlw==', '6K+36L6T5YWl6aqM6K+B56CB5Zu+54mH5LitPGZvbnQgY29sb3I9InllbGxvdyIgc2l6ZT0iNCIgc3R5bGU9ImJhY2tncm91bmQ6I0MwQzBDMCI+6buE6ImyPC9mb250PuaWh+Wtlw==', '6K+36L6T5YWl6aqM6K+B56CB5Zu+54mH5LitPGZvbnQgY29sb3I9ImJsdWUiIHNpemU9IjQiIHN0eWxlPSJiYWNrZ3JvdW5kOiNDMEMwQzAiPuiTneiJsjwvZm9udD7mloflrZc=', '57O757uf57mB5b+Z77yM6K+356iN5ZCO6YeN6K+VIQ==', 'Z2V0VGltZQ==', 'cmVhZHk=', 'I2ZwZG0=', 'Ymx1cg==', 'I3l6bV91bnVzZV9pbWc=', 'aGlkZQ==', 'I3l6bV9pbWc=', 'c2hvdw==', 'cHJpY29kZQ==', 'Y2xlYXJB', 'dmFs', 'dHJpbQ==', 'L3l6bVF1ZXJ5', 'dG9TdHJpbmc=', 'I2ZwaG0=', 'I2tqamU=', 'cmFuZG9t', 'bm55ZA==', 'eXpt', 'YWpheFNldHVw', 'YWpheA==', 'cG9zdA==', 'anNvbnA=', 'Y2FsbGJhY2s=', 'aGFzT3duUHJvcGVydHk=', 'ZGF0YQ==', 'ZGVjb2Rl', 'a2V5MQ==', 'a2V5Mg==', 'a2V5Mw==', 'a2V5NA==', 'a2V5NQ==', 'a2V5Ng==', 'MDAz', '6aqM6K+B56CB6K+35rGC5qyh5pWw6L+H5LqO6aKR57mB77yM6K+3MeWIhumSn+WQjuWGjeivle+8gQ==', 'MDA1', '6Z2e5rOV6K+35rGCIQ==', 'MDEw', '572R57uc6LaF5pe277yM6K+36YeN6K+V77yBKDAxKQ==', 'ZnBkbWVycg==', '6K+36L6T5YWl5ZCI5rOV5Y+R56Wo5Luj56CBIQ==', 'MDI0', 'MjTlsI/ml7blhoXpqozor4HnoIHor7fmsYLlpKrpopHnuYHvvIzor7fnqI3lkI7lho3or5XvvIE=', 'MDE2', '5pyN5Yqh5Zmo5o6l5pS255qE6K+35rGC5aSq6aKR57mB77yM6K+356iN5ZCO5YaN6K+V77yB', 'MDIw', '55Sx5LqO5p+l6aqM6KGM5Li65byC5bi477yM5raJ5auM6L+d6KeE77yM5b2T5YmN5peg5rOV5L2/55So5p+l6aqM5pyN5Yqh77yB']

def get_eab23js():
    """
    获取eab23js文件
    """
    # 读文件
    # 1.获取当前文件 读文件操作.py 的路径
    abs = os.path.abspath(__file__)
    # 找到上级目录 dirname
    path = os.path.dirname(abs)
    base_dir = os.path.dirname(os.path.abspath(__file__))
    # 路径拼接 ()可以跟多了路径
    file_path = os.path.join(base_dir, "eab23.html")
    # 2.判断文件是否存在
    if not os.path.exists(file_path):
        print("文件夹不存在就创建")
    # os.makedirs(file_path)
    else:
        # 字节读取
        file_object = open(file_path, mode='rb')
        data = file_object.read()
        file_object.close()
        text = data.decode('utf-8')
        # 文本读取
        file_text = open(file_path, mode='rt', encoding='utf-8')
        file_message = file_text.read()
        file_text.close()
    return file_message

if __name__ == "__main__":
    my_jiemishuzu_dict = {}

    jiemishuzu = arrayjm.jm_array(_0x56af,14)
    for item in range(len(jiemishuzu)):
        my_jiemishuzu_dict[f"""_0xe6a9('{hex(item)}')"""] = jiemishuzu[item]
    # print(my_jiemishuzu_dict)
    js_message = get_eab23js()
    pattern = '_0xe6a9\(\'0x.*?\'\)'

    list_t = re.findall(pattern, js_message)

    newstr = js_message
    for key, value in my_jiemishuzu_dict.items():
        newstr = newstr.replace(f"""{key}""", f"'{value}'")
    print(newstr)
